package com.eclipse.e0112_jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class jdbc_try {
	public static void main(String[] args) {
		
		ResultSet resultSet = null;
		Connection connection = null;
		PreparedStatement statement = null;
		
		try {
			// 加载驱动
			Class.forName("com.mysql.cj.jdbc.Driver");
			// 打开链接
			connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/login", "root", "qq123123");
			// 获取sql语句
			statement = connection.prepareStatement("insert into admin(user,password) values(?,?)");
			// 第1个问号放入9
			statement.setObject(1, 9);
			
			// 第2个问号放入7
			statement.setObject(2, 7);
			// 执行放入命令
//			statement.executeQuery();
			statement.executeUpdate();
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {
				if (resultSet != null) {
					resultSet.close();
				}
				if (statement != null) {
					statement.close();
				}
				if (connection != null) {
					connection.close();
				}
			} catch (SQLException ex) {
				ex.printStackTrace();
			}
		}
	}
}
